<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
		<meta charset="utf-8" />
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
	  <ul class="forminfo" style="margin-top: 20px;">
    	<li><label>单位名称</label><input name="Name" type="text" class="dfinput" maxlength="20"></li>
    	<li><label>单位地址</label>省份：<select id="dpselect" name="TheProvince"  class="forminfo_select" onchange="selectChanged();">
						<c:forEach items="${provinceList}" var="province">
							<option value="${province.provinceId }" >${province.provinceName }</option>
						</c:forEach>
					</select>
							城市：<select id="TheCity"  name="TheCity" class="forminfo_select" >
						<c:forEach items="${cityList}" var="city">
							<option value="${city.cityId }"  >${city.cityName }</option>
						</c:forEach>
					</select>
				<input name="TheAddress" type="text" class="dfinput" placeholder="具体地址" style="margin-left:130px;margin-top:10px;" maxlength="40">
    	</li>
    	<li><label>单位联系人</label><input name="TheContact" type="text" class="dfinput" maxlength="4"></li>
    	<li><label>电话</label><input name="TheContactPhone" id="TheContactPhone" type="text" class="dfinput"  maxlength="15" onblur="phoneOnblur()"></li>
    	 <li><label>单位简介</label><textarea class="long_text long_text2" name="TheIntroduce" maxlength="100"></textarea></li>
	<li><label>&nbsp;</label><input name="" type="button" class="btn"  onclick="submitForm()"  value="确认保存"/></li>
    </ul>
</body>
	<script type="text/javascript" src="js/jquery-1.7.2.js" ></script>
	<script type="text/javascript" src="js/jquery.tips.js"></script>
	<script type="text/javascript" src="layer/layer.js" ></script>
<script type="text/javascript">
function selectChanged() {
	 var ele=document.getElementById('dpselect');
	  	var index=ele.selectedIndex;
	 	 var val=ele.options[index].value;
	 	$.ajax({
		type: "POST",
		url: "enterpriseinfo/province.do",
		data: { ProvinceId : val},
		async: true,
		dataType: "json",
		success: function(data) {
			$("#TheCity").empty();
			for(var i in data.cityList){  
				var $str = "<option value="+data.cityList[i].cityId +">"+data.cityList[i].cityName +"</option>";
				$("#TheCity").append($str);  	 
			}}
		})
		}

function phoneOnblur(){
 	var inp = document.getElementById("TheContactPhone");
	var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
	var result = reg.test(inp.value);
	if (!result) {
		showTips($("input[name='TheContactPhone']"), '手机号格式不对，请重新输入!！');
		return false;
	}
}
function submitForm() {
	if ($("input[name='Name']").val() == "") {
		showTips($("input[name='Name']"), '请填写单位名称!');
		return false;
	}
	if ($("input[name='TheAddress']").val() =="") {
		showTips($("input[name='TheAddress']"), '请填写单位具体地址!');
		return false;
	}
	if ($("input[name='TheContact']").val() =="") {
		showTips($("input[name='TheContact']"), '请填写单位联系人!');
		return false;
	}
	if ($("input[name='TheContactPhone']").val() =="") {
		showTips($("input[name='TheContactPhone']"), '请填写电话!');
		return false;
	}
	if ($("textarea[name='TheIntroduce']").val() == "") {
		showTips($("textarea[name='TheIntroduce']"), '请填写单位简介!');
		return false;
		}
	var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
	var result = reg.test($("input[name='TheContactPhone']").val());
	if (!result) {
		showTips($("input[name='TheContactPhone']"), '手机号格式不对，请重新输入!！');
		return false;
	}
	 
		var ele = document.getElementById('dpselect');
		var index = ele.selectedIndex;
		var val = ele.options[index].value;
		var TheCity = document.getElementById('TheCity');
		var index1 = TheCity.selectedIndex;
		var val1 = TheCity.options[index1].value;
		$.ajax({
			type : "POST",
			url : "enterpriseinfo/enterpriseinfo_save.do",
			data : {
				Name : $("input[name='Name']").val(),
				provinceId :val,
				cityId : val1,
				TheAddress : $("input[name='TheAddress']").val(),
				TheContact : $("input[name='TheContact']").val(),
				TheContactPhone : $("input[name='TheContactPhone']").val(),
				TheIntroduce : $("textarea[name='TheIntroduce']").val()
			},
			async : true,
			dataType : "json",
			success : function(data) {
				if ("success" == data.result) {
					parent.closeAll();
				} else {
					layer.alert('添加失败!', {
						skin : 'layer-ext-moon'
					});
				}
			}
		})
	}
	function showTips(obj, tips) {
		obj.tips({
			side : 3,
			msg : tips,
			bg : '#e69138',
			time : 2
		});
	}
</script>
</html>
